<template>
  <qx-table :option="tableOption" :remoteData="remoteData"
            class="no-shadow no-padding bg-transparent non-margin-top q-mt-sm"></qx-table>
</template>

<script setup>
import { i18n } from 'boot/i18n'
import { computed, onMounted, ref } from 'vue'

const emits = defineEmits(['click'])

const remoteData = ref({ dicUrl: '/tpm/yfagv/api/cmMaintenanceStrategy/task/list' })
const tableOption = computed(() => {
  return {
    page: false, index: false,
    column: [{
      label: `${i18n.t('AGVCore.AGVCode')}`, field: 'equipmentNo', minWidth: 60
    }, {
      label: `${i18n.t('Misc.MaintenanceStatusTip1')}`, field: 'executing', minWidth: 60,
      cellClick: handleClick
    }, {
      label: `${i18n.t('Misc.MaintenanceStatusTip2')}`, field: 'executed', minWidth: 60,
      cellClick: handleClick
    }, {
      label: `${i18n.t('Misc.MaintenanceStatusTip3')}`, field: 'exceed', minWidth: 80,
      cellClick: handleClick
    }]
  }
})

const handleClick = (row = {}, col = {}) => {
  if (col.field === 'equipmentNo') return
  const params = { equipmentNo: row.equipmentNo, executedDay: col.field === 'executed' ? '30' : '', action: 'exec' }
  if (col.field === 'executing') row.executeStatus = '0'
  else if (col.field === 'executed') row.executeStatus = '1'
  else if (col.field === 'exceed') row.executeStatus = '2'
  emits('click', params)
}

const formatSearchForm = () => ({ nonLoadingBar: true, executedDay: 30 })
const startSearch = (_, done) => {
  remoteData.value.params = formatSearchForm()
  remoteData.value.clearSelected = true
  if (done) done()
}
onMounted(startSearch)
</script>